package com.lh.servlet.method2;

import com.lh.servlet.MyServlet01;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServlet;

/**
 * Servlet手动实现方法二的配置类
 *
 * @Author LuoHang
 * @Date 2022-05-10 19:12
 **/
@Configuration
public class MyServletConfig {
    /**
     * 定义方法注册servlet对象
     */
    @Bean
    public ServletRegistrationBean<HttpServlet> servletRegistrationBean(){
        //第一个对象servlet对象，第二个参数url地址
        //第一种方式：ServletRegistrationBean bean = new ServletRegistrationBean(new MyServlet(),"/myServlet")
        //第二种
        ServletRegistrationBean<HttpServlet> bean = new ServletRegistrationBean<>();
        bean.setServlet(new MyServlet02());
        //指定路由/myServlet02,/myServlet03都由MyServlet02这个Servlet类处理
        bean.addUrlMappings("/myServlet02","/myServlet03");
        return bean;
    }
}
